<?php
namespace yunj\validate;

use yunj\Validate;

class YunjImport extends Validate {

    protected $rule = [
        'builder_id' => 'require',
        'builder_async_type' => 'require|in:import',
        'rows' => 'require|array',
    ];

    protected $message = [
        'builder_id.require' => '访问错误',
        'builder_async_type.require' => '[builder_async_type]参数缺失',
        'builder_async_type.in' => '[builder_async_type]参数错误',
        'rows.require' => '[builder_async_type]参数缺失',
        'rows.array' => '[rows]参数错误',
    ];

    protected $scene = [
        'async_request'=>['builder_id',"builder_async_type",'rows'],
    ];

    protected function handleData(array $raw_data,$scene): array {
        $data=$raw_data;
        if($scene=='async_request'){
            switch ($data['builder_async_type']){
                case "import":
                    $this->handleDataByImport($data);
                    break;
            }
        }
        return $data;
    }

    private function handleDataByImport(&$data){
        $data["count"] = count($data['rows']);
        return $data;
    }

}